//
//  VisitorLoginView.swift
//  新浪微博
//
//  Created by 李赛 on 15/5/10.
//  Copyright (c) 2015年 李赛. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate : NSObjectProtocol{
    
    // 注册按钮代理方法
    func didSelectedRegisterButton()
    // 登录按钮代理方法
    func didSelectedLoginButton()
    
}

class VisitorLoginView: UIView {

    // 定义代理属性   代理用weak
    weak var delegate : VisitorLoginViewDelegate?
    
    @IBOutlet weak var smallIconView: UIImageView!
    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var messageLabel: UILabel!
    
    @IBAction func register() {
        println("\(__FUNCTION__)")
        delegate?.didSelectedRegisterButton()
    }
    
    @IBAction func login() {
        println("\(__FUNCTION__)")
        delegate?.didSelectedLoginButton()
    }
    
    // 设置访客视图信息
    func setupInfo(iconName:String ,message:String , isHome:Bool = false){
        iconView.hidden = !isHome
        if isHome{
            iconView.image = UIImage(named: iconName)
            smallIconView.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        }else{
            smallIconView.image = UIImage(named: iconName)
        }
        messageLabel.text = message
        
        // 判断是否首页  然后是否执行动画效果
        isHome ? startAnimation() : stopAnimation()
    }
    
    /// 开始动画
    func startAnimation(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        // 设置动画属性
        anim.duration = 20.0
        anim.repeatCount = MAXFLOAT
        anim.toValue = M_PI * 2.0
        // 执行动画
        smallIconView.layer.addAnimation(anim, forKey: nil)
    }
    
    /// 停止动画
    func stopAnimation(){
        smallIconView.layer.removeAllAnimations()
    }
    
}
